<?php

namespace app\admin\controller\mbti;

use app\common\controller\Backend;
use think\Db;
/**
 * 测评结果管理
 *
 * @icon fa fa-circle-o
 */
class Evaluate extends Backend
{

    /**
     * MbtiEvaluate模型对象
     * @var \app\admin\model\MbtiEvaluate
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\MbtiEvaluate;
        $this->view->assign("viewStatusList", $this->model->getViewStatusList());
    }

    /**
     * @param $ids
     * @return mixed
     * 选择答案列表
     */
    public function answer_list($ids)
    {
        $row = $this->model->where('id', $ids)->find();
        $answers_data = unserialize($row["answers"]);
        $sceneInfo = \app\admin\model\MbtiScene::get($row["scene_id"]);
        $tempConfig = config('mbti_' . $sceneInfo["version"]);
        $this->view->assign('question_list', $tempConfig);
        $this->view->assign('row', $row);
        $this->view->assign('answers_data', $answers_data);
        return $this->view->fetch();
    }

    public function mbti_result($ids){
        $row = $this->model->where('id', $ids)->find();
        if($row){
            $resultCondition = [
                'scene_id'=>$row["scene_id"],
                'sex'=>$row["sex"],
                'mbti_ie' => ["IN", ["A", $row['mbti_ie']]],
                'mbti_sn' => ["IN", ["A", $row['mbti_sn']]],
                'mbti_tf' => ["IN", ["A", $row['mbti_tf']]],
                'mbti_pj' => ["IN", ["A", $row['mbti_pj']]]
            ];
            $sceneInfo = \app\admin\model\MbtiScene::get(['id'=>$row["scene_id"]]);
            $this->view->assign('scene_info', $sceneInfo);
            $resultInfo = \app\admin\model\MbtiResult::get($resultCondition);
            $this->view->assign('result_info', $resultInfo);
            $userInfo = Db::name("user")->where(["id"=>$row["user_id"]])->find();
            $this->view->assign('mbti_user', $userInfo);
        }
        $this->view->assign('row', $row);
        return $this->view->fetch();
    }

    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


}
